{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.array([[1,1],\n",
    "            [0,1]])\n",
    "b = np.arange(4).reshape((2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "c = a*b\n",
    "c_dot = np.dot(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1]\n",
      " [0 3]]\n",
      "[[2 4]\n",
      " [2 3]]\n"
     ]
    }
   ],
   "source": [
    "print(c)\n",
    "print(c_do)#矩阵乘法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.6249169   0.65724308  0.95880385  0.65105475]\n",
      " [ 0.72734332  0.9905196   0.42527533  0.66334559]]\n",
      "[ 2.89201858  2.80648383]\n",
      "[ 0.6249169   0.65724308  0.42527533  0.65105475]\n",
      "0.990519598781\n"
     ]
    }
   ],
   "source": [
    "d = np.random.random((2,4))\n",
    "print(d)\n",
    "print(np.sum(d,axis=1))#axi=0是列，axis=1是行\n",
    "print(np.min(d,axis=0))\n",
    "print(np.max(d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "11\n",
      "7.5\n",
      "7.5\n",
      "7.5\n",
      "[ 2  5  9 14 20 27 35 44 54 65 77 90]\n",
      "(array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], dtype=int64), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=int64))\n"
     ]
    }
   ],
   "source": [
    "A = np.arange(2,14).reshape((3,4))\n",
    "print(np.argmin(A))\n",
    "print(np.argmax(A))#加arg是加索引，要其索引位置\n",
    "print(np.mean(A))\n",
    "print(np.average(A))\n",
    "print(np.median(A))\n",
    "print(np.cumsum(A))#累加\n",
    "print(np.nonzero(A))#非零的是哪些"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[14 13 12 11]\n",
      " [10  9  8  7]\n",
      " [ 6  5  4  3]]\n",
      "[[11 12 13 14]\n",
      " [ 7  8  9 10]\n",
      " [ 3  4  5  6]]\n",
      "[[14 10  6]\n",
      " [13  9  5]\n",
      " [12  8  4]\n",
      " [11  7  3]]\n",
      "[[14 10  6]\n",
      " [13  9  5]\n",
      " [12  8  4]\n",
      " [11  7  3]]\n",
      "[[9 9 9 9]\n",
      " [9 9 8 7]\n",
      " [6 5 5 5]]\n",
      "[  3.5   7.5  11.5]\n",
      "[ 6.  7.  8.  9.]\n"
     ]
    }
   ],
   "source": [
    "B = np.arange(14,2,-1).reshape((3,4))#从14到2步长是-1\n",
    "print(B)\n",
    "print(np.sort(B))#逐行排序\n",
    "print(np.transpose(B))\n",
    "print(B.T)\n",
    "print(np.clip(B,5,9))\n",
    "print(np.mean(A,axis=1))\n",
    "print(np.mean(A,axis=0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
